package org.mendoza.salud.hvt.validation;

import org.mendoza.salud.hvt.model.AbstractEntity;

import javax.annotation.Resource;
import javax.enterprise.context.RequestScoped;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by administrador on 16/10/14.
 */
@RequestScoped
public class PropertiesValidator {
    @Resource
    private Validator validator;

    public <T extends AbstractEntity> Set<ConstraintViolation<T>> getViolations(T entidad) {
        return validator.validate(entidad);
    }

    public <T extends AbstractEntity> Set<String> getVilolationsMessages(T entidad) {
        Set<String> messages = new HashSet<String>();
        for (ConstraintViolation<T> violation : getViolations(entidad)) {
            messages.add(violation.getMessage());
        }
        return messages;
    }

}
